﻿// Study0305.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// 第三章：函数
// 计算分段函数

#include <iostream>;

using namespace std;
unsigned long Jiecheng(unsigned int n) {
    unsigned long sum{ 1 };
    for (unsigned int i = 1; i <=n; i++)
    {
        sum *= i;
    }
    return sum;
}
double tsin(double x) {
    double m = x;
    double sum=0;
    int i{ 1 }, j{ 1 };
    while (fabs(m/j)>1e-10)
    {
        sum = (i % 2 == 1) ? sum + m / j : sum - m / j;
        m *= (x * x);
        i++;
        j =Jiecheng( 2 * i - 1);
    }
    return sum;
}

int main()
{
    double r, s,result;
    cout << "输入r的值：";
    cin >>r;
    cout << endl;
    cout << "输入s的值：";
    cin >> s;
    cout << endl;
    if (r*r<=s*s)
    {
        result = sqrt(tsin(r) * tsin(r) + tsin(s) * tsin(s));
    }
    else
    {
        result = tsin(r * s) / 2;
    }
    cout << "结果k为：" << result << endl;
    return 0;
}


